<?php
/*
Plugin Name: 泽优Word一键粘贴插件
Plugin URI: http://www.ncmem.com
Description: 帮助您将Word中的文字和图片一键上传到博客中。
Version: 1.0
Author: zysoft
Author URI: http://www.ncmem.com/
*/

require_once('wordpaster_class.php');
add_action('personal_options_update', array(&$wordpaster, 'user_personalopts_update'));
add_action('admin_head', array(&$wordpaster, 'add_admin_head'));
add_action('edit_form_advanced', array(&$wordpaster, 'load_wordpaster'));
add_action('edit_page_form', array(&$wordpaster, 'load_wordpaster'));
add_action('simple_edit_form', array(&$wordpaster, 'load_wordpaster'));
add_action('admin_print_styles', array(&$wordpaster, 'add_admin_style'));
add_action('admin_print_scripts', array(&$wordpaster, 'add_admin_js'));
if ( get_option('ke_auto_highlight') == 'yes' )
{
    //add_action('wp_enqueue_scripts', array(&$wordpaster, 'add_head_script'));
    //add_action('wp_enqueue_scripts', array(&$wordpaster, 'add_head_style'));
}
register_activation_hook(basename(dirname(__FILE__)).'/' . basename(__FILE__), array(&$wordpaster, 'activate'));
register_deactivation_hook(basename(dirname(__FILE__)).'/' . basename(__FILE__), array(&$wordpaster, 'deactivate'));

// Array of options and their default values.
global $wordpaster_options;
$wordpaster_options = array (
    'wordpaster_license' => '',
    'wordpaster_posturl' => '',
);

//设置页面
function wordpaster_option_page()
{
    if ( !empty($_POST) && check_admin_referer('wordpaster_admin_options-update') ) {
        update_option('wordpaster_license', $_POST['wordpaster_license']);
        echo '<div id="message" class="updated">保存成功...</div>';
    }
    ?>
    <div class="wrap">
        <h2>WordPaster设置</h2>
        <p>欢迎来到WordPaster for wordpress的设置页面。</p>
	    <p>使用前请先安装控件：<a href="http://www.ncmem.com/webapp/wordpaster/pack.aspx" target="_blank">安装控件</a>。</p>
        <form action="<?php echo admin_url('options-general.php?page=wordpaster-options') ?>" method="post" id="">
            <table class="form-table">
                <tr valign="top">
                    <th scope="row"><label for="wp2wb_app_key">授权码</label></th>
                    <td>
                        <textarea name="wordpaster_license" id="wordpaster_license" style="height:100px;width:100%;" class="regular-text" ><?php print( get_option( 'wordpaster_license' ) ); ?></textarea>
                    <p class="description">请输入你的授权码，注意：localhost域名下面不需要输入授权码。</p></td>
                </tr>
                <tr valign="top">
                    <th>
                        <input type="submit" name="submit" class="button-primary" value="保存设置" />
                    </th>
                    <td></td>
                </tr>            
            <?php wp_nonce_field('wordpaster_admin_options-update'); ?>
        </form>
    </div>
    <?php
}
function wordpaster_plugin_page()
{
    add_options_page('wordpaster settings', 'WordPaster设置','manage_options', 'wordpaster-options', 'wordpaster_option_page');
}

add_action('admin_menu', 'wordpaster_plugin_page');

//添加设置链接
if ( !function_exists('wordpaster_action_links') ) {
    add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'wordpaster_action_links' );
    function wordpaster_action_links ( $links ) {

        $setting_links = array (
            'settings' => '<a href="' . admin_url( 'options-general.php?page=wordpaster-options').'">'.'设置'.'</a>'
        );

        return array_merge( $setting_links, $links);
    }
}
?>